import { cloud } from '@hw-agconnect/cloud-server';
import { sys_role } from './sys_role'; // BookInfo是Server Model

// default是BookInfo对象类型使用的存储区名
const collection = cloud.database({ zoneName: 'default' }).collection(sys_role);


export class SysRoleObj {
  query() {
    return collection.query().get();
  }


  upset(sys_roles: sys_role[]) {
    return new Promise((resolve, reject) => {
      collection.upsert(sys_roles.map(s_role => sys_role.parseFrom(s_role)))
        .then(result => resolve({ result }))
        .catch(err => reject(err))
    });
  }
}
